//
//  UIView+Progress.m
//  BorrowDrawingBook
//
//  Created by QA on 16/4/14.
//  Copyright © 2016年 QA. All rights reserved.
//

#import "UIView+Progress.h"
#import "JGProgressHUD.h"

#import "JGProgressHUDSuccessIndicatorView.h"
#import "JGProgressHUDErrorIndicatorView.h"

@implementation UIView (Progress)


#pragma mark - JGProgressHUD

- (void)showJGProgressHUDText:(NSString*)text
{
    [self dismiss];
    JGProgressHUD *HUD = [JGProgressHUD progressHUDWithStyle:JGProgressHUDStyleDark];
    HUD.textLabel.text = text;
    [HUD showInView:self];
}

- (void)showJGProgressHUDErrorText:(NSString*)text
{
    [self showJGProgressHUDErrorText:text showInView:self];
}

- (void)showJGProgressHUDSuccessText:(NSString*)text
{
    [self showJGProgressHUDSuccessText:text showInView:self];
}

- (void)dismiss
{
    //移除进度条
    NSArray *viewArray = self.subviews;
    for (id view in viewArray) {
        if ([view isKindOfClass:[JGProgressHUD class]]) {
            JGProgressHUD *customView = view;
            [customView dismiss];
        }
    }
}

#pragma mark - JGProgressHUD

- (void)showJGProgressHUDSuccessText:(NSString*)text showInView:(UIView*)view
{
    [self dismiss];
    JGProgressHUD *HUD = [JGProgressHUD progressHUDWithStyle:JGProgressHUDStyleDark];
    HUD.textLabel.text = text;
    HUD.indicatorView = [[JGProgressHUDSuccessIndicatorView alloc] init];
    [HUD showInView:view];
    [HUD dismissAfterDelay:1.5];
}

- (void)showJGProgressHUDErrorText:(NSString*)text showInView:(UIView*)view
{
    [self dismiss];
    JGProgressHUD *HUD = [JGProgressHUD progressHUDWithStyle:JGProgressHUDStyleDark];
    HUD.textLabel.text = text;
    HUD.indicatorView = [[JGProgressHUDErrorIndicatorView alloc] init];
    [HUD showInView:view];
    [HUD dismissAfterDelay:1.5];
}

@end
